package com.example.demo.Controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.Mapper.HTaskSignInMapper;
import com.example.demo.Pojo.HTaskSignIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/hTaskSignIn")
public class HTaskSignInController {
    @Autowired
    HTaskSignInMapper hTaskSignInMapper;

    @RequestMapping("/getSignInByHTaskId")    //根据HTask的id查询打卡记录，参数：hTaskId
    public String getSignInByHTaskId(HttpServletRequest request){
        QueryWrapper<HTaskSignIn> wrapper = new QueryWrapper<>();
        wrapper.eq("hTaskId",Long.parseLong(request.getParameter("hTaskId")));
        List<HTaskSignIn> hTaskSignIns = hTaskSignInMapper.selectList(wrapper);
        return JSON.toJSONString(hTaskSignIns);
    }

    @RequestMapping("/addSignIn")    //添加一个打卡记录，参数：hTaskId
    public int addSignIn(HttpServletRequest request){
        HTaskSignIn hTaskSignIn = new HTaskSignIn();
        hTaskSignIn.setHTaskId(Long.parseLong(request.getParameter("hTaskId")));
        int insert = hTaskSignInMapper.insert(hTaskSignIn);
        return insert;
    }
}
